<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>
<script>
  // json   是一种轻量级的数据交换格式(前后端交互  => 后端接口返回给前端的一种数据格式)
  // json字符串 (有数组和对象解构的字符串)

  // 组成
  // 外层架构  由数组和对象嵌套组成 (数组对象 [{},{},{}] 对象数组{grade:[]})
  // 组成json的基本数据类型  string,number,boolean,null,array object 不能有undefined,函数
  // 键名都需要用引号包裹 

  // JS对象
  var data = {
    name: "张三",
    age: 18,
    isStudy: true,
    isMoney: undefined,
    msg: { height: "177cm", weight: "72kg" },
    grade: [55, 66, 77],
    say: function () {
      console.log("hello");
    }
  }

  // JS对象转JSON数据(json字符串)
  var str = JSON.stringify(data);
  console.log(str);



  var arr = [{
    goodsId: "A001",
    goodsName: "华为 HUAWEI P40 Pro",
    goodsMsg: "华为 HUAWEI P40 Pro 麒麟990 5G SoC芯片 5000万超感知徕卡四摄 50倍数字变焦 8GB+128GB冰霜银全网通5G",
    goodsImg: "https://img12.360buyimg.com/n7/jfs/t1/139098/11/697/82375/5ee6fcebE11053e13/f5df8e27a0b546c5.jpg",
    goodsPrice: 5988,
  }, {
    goodsId: "A002",
    goodsName: "Apple iPhone 11",
    goodsMsg: "Apple iPhone 11 (A2223) 128GB 黑色 移动联通电信4G",
    goodsImg: "https://img10.360buyimg.com/n7/jfs/t1/41566/13/14792/149059/5d7809a7E99b4ed1b/56ea66c5f8a6f724.jpg",
    goodsPrice: 5999,
  }, {
    goodsId: "A003",
    goodsName: "一加8Pro OnePlus",
    goodsMsg: "一加8Pro OnePlus 1+8Pro 5G手机2K+120Hz 青空色",
    goodsImg: "https://img13.360buyimg.com/n7/jfs/t1/131844/26/2030/179283/5ee212b8E6037a065/8ebdf06de22e64e0.jpg",
    goodsPrice: 5399,
  }, {
    goodsId: "A003",
    goodsName: "小米10pro",
    goodsMsg: "小米10pro 双模5G游戏手机【至高12期分期0首付】 珍珠白 12G+256G",
    goodsImg: "https://img12.360buyimg.com/n7/jfs/t1/130507/6/2419/623986/5eea0995E7333f0e8/7ebbebf5a6312e30.png",
    goodsPrice: 4928,
  }]
  var str = JSON.stringify(arr);
  document.write(str);



</script>

</html>